//
//  ABCMainViewController.swift
//  ABCWeiBo
//
//  Created by 刘斌 on 2017/8/1.
//  Copyright © 2017年 刘斌161040149. All rights reserved.
//

import UIKit

class ABCMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //创建自定义的tabbar
        let tabbar = ABCTabBar()
        // KVC 给只读属性值
        setValue(tabbar, forKey: "tabBar")
        
        addChildViewController(vc: ABCHomeViewController(), title: "首页", imgName: "tabbar_home")
        addChildViewController(vc: ABCMessageViewController(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(vc: ABCDiscoverViewController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(vc: ABCProfileViewController(), title: "我", imgName: "tabbar_profile")

        // Do any additional setup after loading the view.
        
    
    }
    
   /// 添加子控制器
   ///
   /// - Parameters:
   ///   - vc: 对象
   ///   - title: title
   ///   - imgName: 图片名
   private func addChildViewController(vc: UIViewController, title: String, imgName: String) {
        vc.title = title
        //设置图片
        vc.tabBarItem.image = UIImage(named:imgName)?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        vc.tabBarItem.selectedImage =  UIImage(named: "\(imgName)_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
    vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: UIControlState.selected)
        //创建导航控制器
        let nav = UINavigationController(rootViewController: vc)
        //添加子控制器
        addChildViewController(nav)
    }
    



}
